package com.offcn.bigdata.datastream

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.scala._
/**
 * @Auther: BigData-LGW
 * @ClassName: FlinkScalaDataStreamWordCount
 * @Date: 2020/12/15 20:04
 * @功能描述: $FunctionDescription
 * @Version:1.0
 */
object FlinkScalaDataStreamWordCount {
    def main(args: Array[String]): Unit = {
        val env = StreamExecutionEnvironment.getExecutionEnvironment
        env.setParallelism(9)
        val lines = env.socketTextStream("node-1",9999)
        val ret = lines.flatMap(line => line.split("\\s+"))
            .map(word => WordCount(word,1))
            .keyBy("word")
            .sum("count")
        ret.print("wordcount:::").setParallelism(1)
        env.execute(s"${FlinkScalaDataStreamWordCount.getClass.getSimpleName}")
    }
}
case class WordCount(word: String, count: Int)